//


#import "FAMCameraConfirmPhotoViewController.h"

@interface FAMCameraConfirmPhotoViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *FAMImageView;
@property (weak, nonatomic) IBOutlet UIButton *FAMAgainButton;

@end

@implementation FAMCameraConfirmPhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self FAM_showUi];
}
- (void)FAM_showUi{
    self.title = @"Confirm your photo";
    self.FAMAgainButton.layer.borderWidth = 1;
    self.FAMAgainButton.layer.borderColor = kCustom0xColor(0x191919, 1.0).CGColor;
    self.FAMImageView.image = self.FAMSelectedImage;
}
- (IBAction)FAM_againButtonClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)FAM_confirmButtonClick:(UIButton *)sender {
    WeakSelf(self);
    [self showHudInKeyWindowWithHint:nil];
    NSData *imageData = UIImageJPEGRepresentation(self.FAMSelectedImage, 0.5);
    [[FAMUploadSourceManager shared]uploadDataWithData:imageData block:^(NSDictionary * _Nullable request, NSError * _Nullable error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf hideHudKeyWindow];
            if (error) {
                [weakSelf showHint:@"Network abnormality, please try again later"];
            }else
            {
                [weakSelf FAM_nextPage:request];
            }
        });
    }];
//    [FAMHttpTool FAM_UploadImageWithFile:self.FAMSelectedImage success:^(FAMFoodmateUploadModel * _Nonnull model, NSString * _Nonnull msg) {
//        dispatch_async(dispatch_get_main_queue(), ^{
//            [weakSelf hideHudKeyWindow];
//        });
//    } failure:^(NSString * _Nonnull errorInfo) {
//        dispatch_async(dispatch_get_main_queue(), ^{
//            [weakSelf hideHudKeyWindow];
//            [weakSelf showHint:errorInfo];
//        });
//    }];
//
}
- (void)FAM_nextPage:(NSDictionary *)request{
    FAMCameRacaloScanAiViewController *vc = [FAMCameRacaloScanAiViewController new];
    vc.FAMSelectedImage = self.FAMSelectedImage;
    FAMFoodmateUploadModel *FAMFoodImageModel = [FAMFoodmateUploadModel mj_objectWithKeyValues:request];
    vc.FAMFoodImageModel = FAMFoodImageModel;
    vc.FAMCateType = self.FAMCateType;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
